﻿using SSC.Models;
using SSC.PlcConnect;

namespace SSC.Services
{
    public static class Variable 
    {
        private static bool _plcConnectedStatus; 
        public static IPlcConnect PlcConnection { get; set; }
        public static bool PlcConnectedStatus
        {
            get => _plcConnectedStatus;
            set
            {
                if (_plcConnectedStatus != value)
                {
                    _plcConnectedStatus = value;
                    OnPlcStatusChanged?.Invoke(null, _plcConnectedStatus);
                }
            }
        }

        public static event EventHandler<bool> OnPlcStatusChanged;

        #region 当前登录用户
        private static UserModel? _currentUser;
        public static UserModel? CurrentUser
        {
            get => _currentUser;
            set
            {
                if (_currentUser != value)
                {
                    _currentUser = value;
                    OnCurrentUserChanged?.Invoke(null, EventArgs.Empty);
                }
            }
        }
        public static string CurrentUserName => CurrentUser?.UserName ?? string.Empty;
        public static string CurrentUserRole => CurrentUser?.UserBackup ?? string.Empty;

        public static event EventHandler? OnCurrentUserChanged;
        #endregion
    }
}
